package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
	// 打印 Body
	fmt.Println("--- Body ---")
	body, err := io.ReadAll(r.Body)
	if err != nil {
		fmt.Println("Read body error:", err)
	} else {
		fmt.Println(string(body))
	}

	fmt.Println("=== End Request ===\n")

	// 返回响应
	w.Write([]byte("ok"))
}

func main() {
	http.HandleFunc("/", handler)

	fmt.Println("服务已启动，监听端口 8086，按 Ctrl+C 退出")
	err := http.ListenAndServe(":8086", nil)
	if err != nil {
		log.Fatal("服务启动失败:", err)
	}
}
